import { defineStore } from "pinia";

export const useCounterStore = defineStore(
  "counter",
  () => {
    const count = ref(0);
    const doubleCount = computed(() => count.value * 2);
    function increment() {
      count.value++;
    }

    function decrement() {
      count.value--;
    }

    return {
      count,
      doubleCount,
      increment,
      decrement,
    };
  },
  {
    persist: {
      // 不需要持久化，配置项 persist: false
      storage: sessionStorage, // 可以是 localStorage, sessionStorage 或 window.localStorage
      key: "counter_key", // 状态的键名
    },
  }
);
